package com.technology.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.GenericServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;

/**
 * Servlet implementation class GenericServletUsing
 */
public class GenericServletUsing extends GenericServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException {
		System.out.println(config.getInitParameter("param"));
	}

	/**
	 * @see Servlet#destroy()
	 */
	public void destroy() {
		System.out.println("Destroy servlet");
	}

	/**
	 * @see Servlet#service(ServletRequest request, ServletResponse response)
	 */
	public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
		String login = request.getParameter("login");
		if (login == null) login = "Default";
		String password = request.getParameter("password");
		if (password == null) password = "password";
		response.setContentType("text/html; charset=utf-8"); 
		
		PrintWriter pw = response.getWriter();
		pw.println("<html>");
			pw.println("<head><title>Generic Servlet Test</title></head>");
			pw.println("<body>");
				pw.println("<label for=\"login\">Login:</label>");
				pw.println("<span id=\"login\" name=\"login\">" + login + "</span>");
//				pw.println("<input type=\"text\" id=\"login\" name=\"login\" value=\"" + login + "\"/>");
				
				pw.println("<label for=\"password\">Password:</label>");
				pw.println("<span id=\"login\" name=\"login\">" + password + "</span>");
//				pw.println("<input type=\"password\" id=\"password\" name=\"password\" value=\"" + password + "\"/>");
			pw.println("</body>");		
		pw.println("</html>");
		
	}

}
